<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //写出验证用户名的正则表达式，用户名只能输入英文、数字和下划线。
        var str = "_1cws";
        var username = /^\w+/;
        document.write(str.match(username));

        //验证用户密码,长度在6~18 之间，只能包含英文和数字。
        var str = "a666666";
        var root = /^[A-Z a-z 0-9]{6,18}$/;
        document.write(str.match(root));

        //qq号码
        var str = "3138128901";
        var qq = /^[1-9][0-9]{4,10}$/;
        document.write(str.match(qq));

        //身份证号码
        var str = "36028120021004666x";
        var iD = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
        document.write(str.match(iD));

        //车牌号       
        var str = "赣A66666";
        var driving = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;
        document.write(str.match(driving));
        
        // ip地址 
        var str = "100.4.5.6";
        var ip = /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/;
        document.write(str.match(ip));
        </script>
</body>
</html>